//package invest;
//
//import invest.data.DataEnum;
//import invest.data.DataFactory;
//import invest.data.getdata.StockRealTimeData;
//import invest.mapper.StockHistoryMapper;
//import invest.model.Profit;
//import invest.model.Record;
//import invest.model.StockHistoryModel;
//import invest.pojo.datapojo.KlineHistory;
//import invest.pojo.datapojo.Stock;
//import invest.pojo.datapojo.StockHistory;
//import org.apache.commons.lang.time.DateUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.Date;
//import java.util.List;
//
//
//@Component
//public class ImportData implements CommandLineRunner {
//    @Autowired
//    StockHistoryMapper stockHistoryMapper;
//
//    @Override
//    public void run(String... args) throws Exception {
//        int holdDays = 5;
//
//        DataFactory realtimeDataFactory = new DataFactory();
//        List<Stock> stockList= (List<Stock>) realtimeDataFactory.getData(DataEnum.STOCK_REALTIME);
//        for (Stock s: stockList) {
//            realtimeDataFactory = new DataFactory(s.getSymbol(),5000);
//            List<KlineHistory> stockKlines=null;
//            try {
//                stockKlines= (List<KlineHistory>) realtimeDataFactory.getData(DataEnum.STOCK_HISTORY);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//
//            List<StockHistoryModel> stockHistoryModels = new ArrayList<>();
//            if (stockKlines != null) {
//                for (KlineHistory k : stockKlines) {
//                    StockHistoryModel stockHistoryModel = new StockHistoryModel();
//                    stockHistoryModel.setCode(s.getSymbol());
//                    stockHistoryModel.setName(s.getName());
//                    stockHistoryModel.setDate(k.getDate());
//                    stockHistoryModel.setHighestPrice(k.getHigh());
//                    stockHistoryModel.setLowestPrice(k.getLow());
//                    stockHistoryModel.setAmount(k.getAmount());
//                    stockHistoryModel.setVolume(Double.valueOf(k.getVolume()));
//                    stockHistoryModel.setRiseNumber(k.getChg());
//                    stockHistoryModel.setRiseRange(k.getPercent());
//                    stockHistoryModel.setClosingPrice(k.getClose());
//                    stockHistoryModel.setOpeningPrice(k.getOpen());
//                    stockHistoryModels.add(stockHistoryModel);
//                }
//                Thread.sleep(400);
//                Collections.reverse(stockHistoryModels);
//                try {
//                    stockHistoryMapper.batchStockHistoryInsert(stockHistoryModels);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//            }
//
//        }
//
//        System.out.println("finish");
//
//
//    }
//
//    private boolean insertDataBase(Record record) throws InterruptedException {
//        System.out.println(record.getName());
//        System.out.println(record.getDate());
//        for (int i = 0; i < 30; i++) {
//            try {
//                stockHistoryMapper.insertRecord(record);
//                return true;
//            } catch (Exception e) {
//                e.printStackTrace();
//                Thread.sleep(6000);
//            }
//        }
//        return false;
//    }
//
//}
//
//
//
